<?php
class Pageley_Commerce_QueryTests extends Pageley_Commerce_DomainTests {
    
    public function testListCategories() {
        $success = $this->dispatchRequest(array(
            "controller" => "Commerce/ListCategories"
        ));
        $this->assertTrue($success);
        $categories = $_REQUEST["commerce.categories"];
        $this->assertNotNull($categories);
        $this->assertEquals(2, $categories->size());
    }

    public function testGetCategory() {
        $success = $this->dispatchRequest(array(
            "controller" => "Commerce/GetCategory",
            "categoryId" => "1"
        ));
        $this->assertTrue($success);
        $category = $_REQUEST["commerce.category"];
        $this->assertNotNull($category);
        $articles = $category->get("articles");
        $this->assertNotNull($articles);
        $this->assertEquals(3, $articles->size());
    }

    public function testListMostRecentArticles() {
        $success = $this->dispatchRequest(array(
            "controller" => "Commerce/ListMostRecentArticles",
            "limitAmount" => "2"
        ));
        $this->assertTrue($success);
        $articles = $_REQUEST["commerce.articles"];
        $this->assertNotNull($articles);
        $this->assertEquals(2, $articles->size());
        $this->assertEquals("Cobra Spray", $articles->get(0)->get("name"));
        $this->assertEquals("Llama Spray", $articles->get(1)->get("name"));
    }

}